'''
Created on 2012-4-9下午9:05:15

@author: yasenagat
@email:   yasenagat@gmail.com

'''

import socket

HOST = 'localhost'                 # Symbolic name meaning all available interfaces
PORT = 12345              # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
print("listen:............... ")
print("host:",HOST,",post:",PORT)
print("wait.................")
while 1:
    conn, addr = s.accept()
    print ('Connected by', addr)
    while 1:
        data = conn.recv(1024)
#        print(repr(data))
#        print(str(data,"utf-8"))
        if not data: break
        
        if  data == bytes("hi","utf-8"):
            print("数据:"+str(data,"utf-8"))
            conn.sendall(bytes("你好，世界","utf-8"))
        else :
            print("其他数据："+str(data,"utf-8"))
            conn.sendall(bytes("其他数据："+str(data,"utf-8"),"utf-8"))
    conn.close()
